#include "Event.h"
#include "../common/Constantes.h"

Event::Event(SDL_Event* event) {
	this->event = event;
}

Event::Event(DTOEvent* dtoEvent) {
	Logger::log("Event", "constructor", "Tipo de evento: " + UtilString::intToString(dtoEvent->type));

	// Armo un SDL_Event
	SDL_Event* event = new SDL_Event();
	event->key.keysym.unicode = dtoEvent->keyUnicode;
	event->type = dtoEvent->type;

	event->resize.h = dtoEvent->h;
	event->resize.w = dtoEvent->w;
	event->button.x = dtoEvent->x;
	event->button.y = dtoEvent->y;
	event->button.y = dtoEvent->y;
	event->user.code = dtoEvent->code;
	event->button.state = dtoEvent->buttonState;
	event->key.keysym.sym = (SDLKey)dtoEvent->key;

	this->sender = dtoEvent->getOwner();


	setEvent(event);
}

Event::~Event() {
	// TODO Auto-generated destructor stub
}

void Event::setEvent(SDL_Event* event) {
	this->event = event;
}

void Event::setSender(std::string sender) {
	this->sender = sender;
}

EventType Event::getType() {
	return (EventType) this->event->type;
}

EventKey Event::getKey() {
	return (EventKey) this->event->key.keysym.sym;
}

EventButtonState Event::getButtonState() {
	return (EventButtonState) this->event->button.state;
}

WindowID Event::getCode() {
	return (WindowID) this->event->user.code;
}

std::string Event::getData() {
	std::string* data;
	data = (std::string*) this->event->user.data1;
	return *data;
}

std::string Event::getData2() {
	std::string* data;
	data = (std::string*) this->event->user.data2;
	return *data;
}

int Event::getintData2() {
	int* data;
	data = (int*) this->event->user.data2;
	return *data;
}

Uint16 Event::getKeyUnicode() {
	return (Uint16) this->event->key.keysym.unicode;
}

Uint16 Event::getXCoordinate() {
	return (Uint16) this->event->button.x;
}

Uint16 Event::getYCoordinate() {
	return (Uint16) this->event->button.y;
}
SDL_Event* Event::getEvent() {
	return this->event;

}

Uint16 Event::getW() {
	return (Uint16) (this->event->resize.w);
}

Uint16 Event::getH() {
	return (Uint16) (this->event->resize.h);
}

/*Maneje sus punteros con responsabilidad..*/
void Event::eraseData() {
	delete (std::string*) this->event->user.data1;
}

DTOEvent* Event::transformInDTO() {
	return new DTOEvent(getKeyUnicode(), getType(), getH(), getW(),
			getXCoordinate(), getYCoordinate(), getCode(), getButtonState(),
			getKey(), sender);
}

std::string Event::getSender() {
	return sender;
}
